package com.mysql.dao.impl;

import com.mysql.dao.J2ee_testDAO;
import com.mysql.entity.J2ee_test;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class J2ee_testDAOImpl implements J2ee_testDAO {

    public J2ee_testDAOImpl() {
    }


    @Override
    public void Insert(Connection conn,J2ee_test j2ee_test) throws SQLException {

        Statement statement=conn.createStatement();

        statement.executeUpdate(
                "INSERT INTO test\n" + "(ID,NAME)\n" + "VALUES("+j2ee_test.getV_no()+",'"+j2ee_test.getV_title()+"')");

        statement.close();
    }

    @Override
    public void Delete(Connection conn, int ID) throws SQLException {

        Statement statement=conn.createStatement();

        statement.executeUpdate("DELETE FROM test \n" + "WHERE ID="+ID);

        statement.close();
    }

    @Override
    public void Updata(Connection conn, int ID,String Name) throws SQLException {
        Statement statement=conn.createStatement();

        statement.executeUpdate(" UPDATE test SET test.Name='"+Name+"' WHERE ID="+ID);

        statement.close();
    }

    @Override
    public J2ee_test Select(Connection conn, int ID) throws SQLException {
        Statement statement=conn.createStatement();

        ResultSet resultSet = statement.executeQuery("select * from video where v_no="+ID);

        resultSet.next();
        int v_no=resultSet.getInt("v_no");
        String v_URL=resultSet.getString("v_URL");
        String v_title=resultSet.getString("v_title");;
        String v_tag=resultSet.getString("v_tag");;
        int v_play=resultSet.getInt("v_play");;
        int v_bullet=resultSet.getInt("v_bullet");;
        int v_like=resultSet.getInt("v_like");;
        int v_coin=resultSet.getInt("v_coin");;
        int v_collection=resultSet.getInt("v_collection");;
        int v_share=resultSet.getInt("v_share");;
        int v_value=resultSet.getInt("v_value");;
        J2ee_test j2ee_test=new J2ee_test(v_no,v_URL,v_title,v_tag,v_play,v_bullet, v_like, v_coin, v_collection,v_share, v_value);
        /*while (resultSet.next()){
            System.out.println("ID="+resultSet.getInt("ID"));
            System.out.println("Name="+resultSet.getString("Name"));
        }*/
        resultSet.close();
        statement.close();
        return j2ee_test;
    }
}
